package com.pjmike.netty.protocol.message.encoder;

import com.pjmike.netty.protocol.message.packet.request.HeartbeatRequestPacket;
import com.pjmike.netty.protocol.message.command.Command;
import com.pjmike.netty.protocol.message.packet.response.HeartbeatResponsePacket;
import com.pjmike.netty.utils.DataTransformUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

import java.util.zip.CRC32;

/**
 * @Author bj
 * @Description //心跳应答报文编码器
 * @Date 9:28 2021/1/10
 * @Param
 * @return
 **/
public class HeartbeatEncoder extends MessageToByteEncoder<HeartbeatResponsePacket> {

    @Override
    protected void encode(ChannelHandlerContext ctx, HeartbeatResponsePacket msg, ByteBuf out) throws Exception {
        //报文头
        short bt = Command.BT;
        out.writeByte((byte)bt);
        //协议号
        out.writeShort(Command.HEARTBEAT_RESPONSE);
        //设备编号
        out.writeBytes(msg.getSbbh().getBytes());
        //数据长度
        out.writeInt(4);
    }
}
